package com.eyolas.passwordmanager.model;

import java.io.Serializable;

import com.eyolas.passwordmanager.dao.CategoryDao;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName="t_category_cat", daoClass=CategoryDao.class)
public class Category implements IModel,Serializable{
	private static final long serialVersionUID = 2937130625258896295L;
	
	@DatabaseField(generatedId=true,columnName="cat_id")
	private int id;
	
	@DatabaseField(canBeNull=false,columnName="cat_name")
	private String name;
	
	private int nbAccount = 0;
	
	/**
	 * Constructeur vide (pour ORMLite)
	 * @author Eyolas
	 * @date 24 mai 2012
	 */
	public Category() {}
	
	/**
	 * Constructeur
	 * @author Eyolas
	 * @date 24 mai 2012
	 * @param name
	 */
	public Category(String name){
		this.name = name;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getNbAccount() {
		return nbAccount;
	}

	public void setNbAccount(int nbAccount) {
		this.nbAccount = nbAccount;
	}
	
	@Override
	public boolean equals(Object o) {
		if (o != null && o instanceof Category) {
			Category cat = (Category)o;
			return getName().equalsIgnoreCase(cat.getName());
		}
		return false;
	}
}
